package com.leapp.sk.ui.activity.personal

import android.os.Bundle
import android.view.View
import com.example.baselibrary.util.LKToastUtil
import com.example.mvp.activity.BaseActivityMVP
import com.example.mvp.binder.BaseDataBinder
import com.example.mvp.view.LKDialog
import com.leapp.sk.R
import com.leapp.sk.app.SKApplication
import com.leapp.sk.binder.BaseBinder
import com.leapp.sk.util.clearAllCache
import com.leapp.sk.util.getTotalCacheSize
import com.leapp.sk.viewdelegate.personal.SettingDelegate

/**
 * 设置
 * @author  chaohaipeng  on 2018/8/8.
 */
class SettingActivity :BaseActivityMVP<SettingDelegate>(){
    /**
     * 开关是否打开
     */
    var isChecked:Boolean=false
    /**
     * 退出登录
     */
    private var lkDialog: LKDialog? = null
    override fun bindEvenListener() {
        viewDelegate.setOnClickListener(View.OnClickListener {
            clearAllCache(SKApplication.getInstance()?.baseContext)
            viewDelegate.setCache(""+0+"K")
            LKToastUtil.showToastShort(resources.getString(R.string.string_setting_toast_clean_data))
        }, R.id.rl_as_cache)

        viewDelegate.setOnClickListener(View.OnClickListener {
            //开关状态 isChecked
            if (isChecked){
                viewDelegate.setPushbtn(false)
                isChecked=false
            }else{
                viewDelegate.setPushbtn(true)
                isChecked=true
            }
        },R.id.iv_as_message_push)

        viewDelegate.setOnClickListener(View.OnClickListener {
            privateMsgDialog()
        },R.id.rl_as_exit_login)
    }
    override fun getDataBinder(): BaseDataBinder<*, *> {
        return BaseBinder()
    }

    override fun initView(p0: Bundle?) {
        viewDelegate.setTitle(resources.getString(R.string.string_setting))
    }

    override fun initDate() {
        val totalCacheSize = getTotalCacheSize(SKApplication.getInstance()?.baseContext)
        viewDelegate.setCache(totalCacheSize)
    }

    override fun getDelegateClass(): Class<SettingDelegate> {
        return SettingDelegate::class.java
    }
    /**
     * 私信发送
     */
    fun privateMsgDialog(){
        if (lkDialog==null){
            lkDialog = LKDialog(this)
            lkDialog?.setMessage(R.string.app_confirm_exit_login)
            lkDialog?.setLeftButton(R.string.app_cancel,View.OnClickListener {
                lkDialog?.dismiss()
            })
            lkDialog?.setRightButton(R.string.app_confirm, View.OnClickListener {
                lkDialog?.dismiss()
                SKApplication.getInstance()?.loginOut(SKApplication.getInstance())
            })

        }
        lkDialog?.show()
    }


}